const express = require('express');

const router = express.Router();

const loginService = require('../service/login');

router.post('/register', async function (req, res, next) {
    // 获取账户名和密码
    let username = req.body.username;
    let password = req.body.password;
    if (!username || !password) {
        return res.json({ success: false, msg: '缺少参数' });
    }
    // 调用业务层
    let result = await loginService.register(username, password);
    return res.json(result);
});

router.post('/login', async function (req, res, next) {
    // 获取账户名和密码
    let username = req.body.username;
    let password = req.body.password;
    if (!username || !password) {
        return res.json({ success: false, msg: '缺少参数' });
    }
    // 调用业务层
    let result = await loginService.login(username, password);
    return res.json(result);
});

module.exports = router;
